<template>
  <FlowBasicListModel
    v-bind="getBindValues"
    :flowTemplate="flowTemplate"
    :callback="getTemplateDefinePage"
    title="申请流程"
  />
</template>
<script lang="ts" setup>
  import { computed, ref, useAttrs, unref } from 'vue';
  import { FlowBasicListModel } from '/@/components/FlowBasicListModel';
  import { getTemplateDefinePageApi } from '/@/api/flow/flow';
  import { FlowTemplateResult } from '/@/api/flow/model';
  import { isString } from '/@/utils/is';

  const loading = ref(false);
  const flowTemplate = ref<FlowTemplateResult[]>([]);

  const attrs = useAttrs();
  const getBindValues = computed(() => {
    return {
      ...attrs,
      loading: unref(loading),
    };
  });

  async function getTemplateDefinePage(ids: any) {
    let arr: string[] = [];

    if (isString(ids)) {
      arr = ids?.split(',');
    }

    loading.value = true;
    const res = await getTemplateDefinePageApi();

    const list = res.filter((item) => !!item.list && item.list.length);

    flowTemplate.value = list.filter((i) => {
      const template = i.list.filter((u) => !arr?.includes(u.templateID.toString()));
      i.list = template;
      return !!i.list && i.list.length;
    });

    loading.value = false;
  }
</script>
<style lang="less" scoped></style>
